package com.yonyou.common.dialog;

import com.intellij.openapi.wm.ToolWindow;

import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.awt.*;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author wengyongcheng
 * @since 2020/3/1 10:30 下午
 */
public class MyToolWindow  {

    private JButton hideButton;

    private JButton dialogButton;

    private JPanel myToolWindowContent = new JPanel();
    private JPanel north = new JPanel();

    private JPanel center = new JPanel();

    private JPanel south = new JPanel();

    private JLabel source_branch = new JLabel("当前分支：");
    private JLabel source_branch_text = new JLabel("无");
    private JLabel target_branch = new JLabel("目标分支：");
    private JLabel target_branch_text = new JLabel("无");

    private JLabel git_token = new JLabel("GIT秘钥：");
    private JTextField git_token_text = new JTextField();

    private JLabel age = new JLabel("年龄：");
    private JTextField ageContent = new JTextField();

    public MyToolWindow(ToolWindow toolWindow) {
        myToolWindowContent.setBorder(BorderFactory.createEmptyBorder(20,20,10,20));

        init();


    }
    public JPanel initNorth() {
        //定义表单的标题部分，放置到IDEA会话框的顶部位置

        JLabel title = new JLabel("表单标题");
        title.setFont(new Font("微软雅黑", Font.PLAIN, 26)); //字体样式
        //title.setHorizontalAlignment(SwingConstants.CENTER); //水平居中
        //title.setVerticalAlignment(SwingConstants.CENTER); //垂直居中
        north.add(title);
        myToolWindowContent.add(north);
        return north;
    }

    private void init() {
        dialogButton = new JButton("触发自定义dialog");
        dialogButton.addActionListener(e -> {
            if (new CustomDialogWrapper1().showAndGet()) {
                // 监听弹框消失，相当于show 和 getExitCode方法的结合
                System.out.println("show and get");
            }
        });

        hideButton = new JButton("取消");


        JPanel title = new JPanel();
        title.setLayout(new GridLayout(3,3));//设置2行3列网格
        JLabel queryLabel = new JLabel("查询条件:");
        queryLabel.setHorizontalAlignment(JLabel.LEFT);
        queryLabel.setVerticalAlignment(JLabel.CENTER);
        JTextField queryTextField = new JTextField(20);
        JButton queryButton = new JButton("查询");
        // 表格的列名
        String[] columnNames = {"ID", "姓名", "年龄", "邮箱"};
        // 模拟数据
        Object[][] data = {
                {"1", "张三", "28", "zhangsan@example.com"},
                {"2", "李四", "32", "lisi@example.com"},
                // ... 更多数据
        };
        // 表格
        JTable resultTable = new JTable(new DefaultTableModel(data, columnNames));

        // 创建一个滚动面板来容纳表格
        JScrollPane scrollPane = new JScrollPane(resultTable);

        // 布局

        title.add(queryLabel);
        title.add(queryTextField);
        title.add(queryButton);
        myToolWindowContent.add(title);
        myToolWindowContent.add(scrollPane);
        myToolWindowContent.setLayout(new BoxLayout(myToolWindowContent, BoxLayout.Y_AXIS));
        myToolWindowContent.add(dialogButton);
        myToolWindowContent.add(hideButton);

    }

    public JPanel getContent() {
        return myToolWindowContent;
    }

}

